package net.zjitc.service.Impl;

import net.zjitc.mapper.DistrictMapper;
import net.zjitc.mapper.MovieMapper;
import net.zjitc.pojo.District;
import net.zjitc.pojo.Movie;
import net.zjitc.service.MovieService;
import net.zjitc.vo.MovieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author admin
 * @Date 2019/5/28 10:22
 */
@Service
@Transactional
public class MovieServiceImpl implements MovieService {
    @Autowired
    MovieMapper movieMapper;
    @Autowired
    DistrictMapper districtMapper;

    @Override
    public List<Movie> findAll() {
        List<Movie>allList = movieMapper.findAll();
        for (Movie m :allList
             ) {
            District district = districtMapper.findById(m.getDis_id());
            m.setDistrict(district);
        }

        return allList;
    }

    @Override
    public List<Movie> show(int showType) {
        List<Movie>list = null;
        switch (showType){
            case 1:
                list =  movieMapper.findByhot();
                break;
            case 2:
                list =  movieMapper.findBydate();
                break;
            case 3:
                list =  movieMapper.findByold();
                break;
            default:
                break;
        }
        return list;
    }

    @Override
    public List<Movie> findByhot() {
        return movieMapper.findByhot();
    }

    @Override
    public int deleteMovie(Integer id) {
        return movieMapper.deleteMovie(id);
    }

    @Override
    public List<Movie> search(MovieVo vo) {
        return movieMapper.search(vo);
    }

    @Override
    public int add(Movie movie) {
        return movieMapper.add(movie);
    }

    @Override
    public List<Movie> index_hot() {
        return movieMapper.index_hot();
    }

    @Override
    public List<Movie> index_date() {
        return movieMapper.index_date();
    }

    @Override
    public List<Movie> index_old() {
        return movieMapper.index_old();
    }

    @Override
    public Movie findById(int movie_id) {
        Movie movie = movieMapper.findById(movie_id);
        District district = districtMapper.findById(movie.getDis_id());
        movie.setDistrict(district);
        return movie;
    }

    @Override
    public List<Movie> findByType_id(Integer type_id) {
        return movieMapper.findByType_id(type_id);
    }

    @Override
    public List<Movie> findByDis_id(Integer dis_id) {
        return movieMapper.findByDis_id(dis_id);
    }

    @Override
    public int update(Movie movie) {
        return movieMapper.update(movie);
    }


}
